<template>
  <a-drawer v-model:visible="LAYER.visible" :title="LAYER.title" :width="LAYER.width"
            :closable="LAYER.closable" :mask-closable="LAYER.maskClosable" :esc-to-close="LAYER.escToClose"
            :unmount-on-close="LAYER.unmountOnClose" :footer="LAYER.footer" :ok-text="LAYER.okText"
            :ok-loading="LAYER.okLoading" :cancel-text="LAYER.cancelText" :on-before-ok="onSubmit" @close="onCancel">
    <!--表单开始-->

    <a-form ref="formRef" :model="formState" layout="vertical" :rules="POSITION_EDIT.RULES">
      <a-row :gutter="12">
        <a-col :span="12">
          <a-form-item label="职务代码" field="code">
            <a-input v-model="formState.code" allow-clear placeholder="请填写职务代码" :disabled="isUpdate"/>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="职务名称" field="name">
            <a-input v-model="formState.name" allow-clear placeholder="请填写职务名称"/>
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <a-form-item label="职务描述" field="description">
            <a-textarea v-model="formState.description" placeholder="请填写职务描述"
                        :auto-size="{ minRows: 2, maxRows: 5 }"/>
          </a-form-item>
        </a-col>

        
      </a-row>


    </a-form>
    <!--表单结束-->
  </a-drawer>
</template>

<script lang="ts" setup>

import {EditDrawer} from '@/libs/core'
import {POSITION_EDIT} from "../resource/form";
import {SystemHttp} from '../resource/http'

const props = defineProps({record: {type: Object, required: true}})
const emit = defineEmits(['cancel'])

const {addPosition, updatePosition} = SystemHttp
const config = {tplRecord: POSITION_EDIT.BODY, rawRecord: props.record, rowKey: 'id', emit}

const service = new EditDrawer(config).setAddRequest(addPosition).setUpdateRequest(updatePosition)
const {formRef, formState, LAYER, isUpdate, onCancel, onSubmit} = service
LAYER.title = isUpdate ? '修改职务' : '新建职务'
</script>
